# -*- coding: utf-8 -*-
from odoo import api, fields, models, tools


class ProductProduct(models.Model):
    _inherit = 'product.product'
    # F2050000623001
    # quality_bool = fields.Boolean(u'是否质检',default=False,store=True)
    # @api.depends('product_tmpl_id.qct_id')
    # def _compute_qc_id(self):
    #     for rcd in self:
    #         rcd.qc_id = rcd.product_tmpl_id.qct_id
    # qc_id = fields.Many2one('quality.check', u'质检方案',compute='_compute_qc_id',readonly=False)
    qc_id = fields.Many2one('quality.check', u'质检方案',store=True)
    # @api.onchange('qc_id')
    # def onchange_qc_id(self):
    #     print 1111
    #     for rcd in self:
    #         print rcd.qc_id.name
    #         self.update({'qc_id':rcd.qc_id.id})
            # rcd.qc_id = rcd.qc_id



class ProductTempalte(models.Model):
    _inherit = 'product.template'

    quality_bool = fields.Boolean(u'产品质检',default=False,store=True)
    qct_id = fields.Many2one('quality.check', u'质检方案',store=True)

    @api.onchange('qct_id')
    def _onchange_qc_id(self):
        if self._origin:
            products = self.env['product.product'].search([('product_tmpl_id','=',self._origin.id)])
        # print varients
            for product in products:
                product.write({'qc_id':self.qct_id.id})

    @api.multi
    def create_variant_ids(self):
        res=super(ProductTempalte, self).create_variant_ids()
        if any(self.qct_id):
            for product in self.product_variant_ids:
                product.write({'qc_id':self.qct_id.id})
        return True





